﻿using AnhAnh;
using Facebook;
using FacebookLib;
using License;
using Microsoft.CSharp.RuntimeBinder;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Entity;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;

namespace AutoSales
{
	public class FormMain : Form
	{
		public static Anh mAnh;

		public static Coca mCoca;

		public static string mToken;

		public static string mLocale;

		public List<GroupData> mGroups = new List<GroupData>();

		public LicenseInfo licenseInfo = new LicenseInfo();

		private BindingSource bindingSource_0 = new BindingSource();

		private bool bool_0 = true;

		private bool bool_1;

		private int int_0;

		private IContainer icontainer_0;

		private Button buttonRun;

		private System.Windows.Forms.Timer timer_0;

		private DataGridView dataGridView1;

		private Button buttonDelete;

		private Button buttonAdd;

		private Button buttonEdit;

		private Button buttonGroupManage;

		private Button buttonSetting;

		private NotifyIcon notifyIcon_0;

		private Button buttonLogin;

		private StatusStrip statusStrip1;

		private ToolStripStatusLabel toolStripStatusLabel1;

		private ToolStripProgressBar toolStripProgressBar1;

		private ToolStripStatusLabel toolStripStatusLabel2;

		private LinkLabel linkLabelHelp;

		private LinkLabel linkLabelReport;

		private Button buttonGroupSearch;

		static FormMain()
		{
			FormMain.mAnh = new Anh();
			FormMain.mToken = string.Empty;
			FormMain.mLocale = string.Empty;
		}

		public FormMain()
		{
			this.InitializeComponent();
		}

		private void buttonAdd_Click(object sender, EventArgs e)
		{
			if (this.method_7())
			{
				(new FormPost(this)).ShowDialog();
			}
		}

		private void buttonDelete_Click(object sender, EventArgs e)
		{
			if (this.dataGridView1.Rows.Count == 0 || this.dataGridView1.SelectedRows.Count == 0)
			{
				return;
			}
			if (UI.ConfirmDelete())
			{
				AutoSalesContext autoSalesContext = new AutoSalesContext();
				for (int i = this.dataGridView1.SelectedRows.Count - 1; i >= 0; i--)
				{
					int num = int.Parse(this.dataGridView1.SelectedRows[i].Cells["id"].Value.ToString());
					DbSet<Post> posts = autoSalesContext.Posts;
					object[] objArray = new object[] { num };
					Post post = posts.Find(objArray);
					autoSalesContext.Posts.Remove(post);
					this.bindingSource_0.RemoveAt(this.dataGridView1.SelectedRows[i].Index);
				}
				autoSalesContext.SaveChanges();
			}
		}

		private void buttonEdit_Click(object sender, EventArgs e)
		{
			if (this.dataGridView1.Rows.Count == 0 || this.dataGridView1.CurrentRow == null)
			{
				return;
			}
			if (this.method_7())
			{
				int num = int.Parse(this.dataGridView1.CurrentRow.Cells["id"].Value.ToString());
				(new FormPost(this, num)).ShowDialog();
			}
		}

		private void buttonGroupManage_Click(object sender, EventArgs e)
		{
			if (this.method_7())
			{
				(new FormGroupManage(this)).Show();
			}
		}

		private void buttonGroupSearch_Click(object sender, EventArgs e)
		{
			if (this.method_7())
			{
				(new FormGroupSearch()).Show();
			}
		}

		private void buttonLogin_Click(object sender, EventArgs e)
		{
			if (this.buttonLogin.Text != "Login")
			{
				if (FormMain.mToken != string.Empty)
				{
					this.method_0("Logout Facebook ..", true, string.Empty, true);
                    //ba4e6bdb66a4ae84f114761050f3c10e
					FormMain.mCoca.Logout(FormMain.mToken);
					FormMain.mToken = string.Empty;
					this.mGroups.Clear();
					this.method_0("Logout success", false, string.Empty, false);
					this.buttonLogin.Text = "Login";
				}
				return;
			}
			this.method_0("Login Facebook ..", true, string.Empty, true);
			string empty = string.Empty;
			string str = string.Empty;
			this.method_8(out empty, out str);
			string empty1 = string.Empty;
            //FormMain.mToken = FormMain.mCoca.Login("1439920419572904", "publish_stream,user_groups,offline_access", empty, str, out empty1);
            FormMain.mToken = FormMain.mCoca.Login("1403351083273327", "publish_stream,user_groups,offline_access", empty, str, out empty1);
            //FormMain.mToken = FormMain.mCoca.Login("486941284765870", "publish_stream,user_groups,offline_access", empty, str, out empty1);
			if (FormMain.mToken == string.Empty)
			{
				this.method_0("Login error", false, string.Empty, false);
				UI.ShowMessage(empty1, "Login", UI.MessageType.Error);
				return;
			}
			FacebookClient facebookClient = new FacebookClient(FormMain.mToken);
			object obj = facebookClient.Get("me/groups", new Class0<string>("id, name, description, privacy, email"));
			this.mGroups.Clear();
			if (FormMain.Class13.callSite_0 == null)
			{
				FormMain.Class13.callSite_0 = CallSite<Func<CallSite, object, IEnumerable>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.None, typeof(IEnumerable), typeof(FormMain)));
			}
			var target = FormMain.Class13.callSite_0.Target;
			CallSite<Func<CallSite, object, IEnumerable>> callSite0 = FormMain.Class13.callSite_0;
			if (FormMain.Class13.callSite_1 == null)
			{
				Type type = typeof(FormMain);
				CSharpArgumentInfo[] cSharpArgumentInfoArray = new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) };
				FormMain.Class13.callSite_1 = CallSite<Func<CallSite, object, object>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags.None, "data", type, cSharpArgumentInfoArray));
			}
			foreach (object target1 in target(callSite0, FormMain.Class13.callSite_1.Target(FormMain.Class13.callSite_1, obj)))
			{
				Application.DoEvents();
				List<GroupData> groupDatas = this.mGroups;
				GroupData groupDatum = new GroupData();
				GroupData groupDatum1 = groupDatum;
				if (FormMain.Class13.callSite_2 == null)
				{
					FormMain.Class13.callSite_2 = CallSite<Func<CallSite, object, string>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.None, typeof(string), typeof(FormMain)));
				}
				var _u00210 = FormMain.Class13.callSite_2.Target;
				CallSite<Func<CallSite, object, string>> callSite2 = FormMain.Class13.callSite_2;
				if (FormMain.Class13.callSite_3 == null)
				{
					Type type1 = typeof(FormMain);
					CSharpArgumentInfo[] cSharpArgumentInfoArray1 = new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) };
					FormMain.Class13.callSite_3 = CallSite<Func<CallSite, object, object>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags.None, "id", type1, cSharpArgumentInfoArray1));
				}
				groupDatum1.id = _u00210(callSite2, FormMain.Class13.callSite_3.Target(FormMain.Class13.callSite_3, target1));
				GroupData target2 = groupDatum;
				if (FormMain.Class13.callSite_4 == null)
				{
					FormMain.Class13.callSite_4 = CallSite<Func<CallSite, object, string>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.None, typeof(string), typeof(FormMain)));
				}
				var _u002101 = FormMain.Class13.callSite_4.Target;
				CallSite<Func<CallSite, object, string>> callSite4 = FormMain.Class13.callSite_4;
				if (FormMain.Class13.callSite_5 == null)
				{
					Type type2 = typeof(FormMain);
					CSharpArgumentInfo[] cSharpArgumentInfoArray2 = new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) };
					FormMain.Class13.callSite_5 = CallSite<Func<CallSite, object, object>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags.None, "name", type2, cSharpArgumentInfoArray2));
				}
				target2.name = _u002101(callSite4, FormMain.Class13.callSite_5.Target(FormMain.Class13.callSite_5, target1));
				GroupData groupDatum2 = groupDatum;
				if (FormMain.Class13.callSite_6 == null)
				{
					FormMain.Class13.callSite_6 = CallSite<Func<CallSite, object, string>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.None, typeof(string), typeof(FormMain)));
				}
				var _u002102 = FormMain.Class13.callSite_6.Target;
				CallSite<Func<CallSite, object, string>> callSite6 = FormMain.Class13.callSite_6;
				if (FormMain.Class13.callSite_7 == null)
				{
					Type type3 = typeof(FormMain);
					CSharpArgumentInfo[] cSharpArgumentInfoArray3 = new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) };
					FormMain.Class13.callSite_7 = CallSite<Func<CallSite, object, object>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags.None, "description", type3, cSharpArgumentInfoArray3));
				}
				groupDatum2.description = _u002102(callSite6, FormMain.Class13.callSite_7.Target(FormMain.Class13.callSite_7, target1));
				GroupData target3 = groupDatum;
				if (FormMain.Class13.callSite_8 == null)
				{
					FormMain.Class13.callSite_8 = CallSite<Func<CallSite, object, string>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.None, typeof(string), typeof(FormMain)));
				}
				var _u002103 = FormMain.Class13.callSite_8.Target;
				CallSite<Func<CallSite, object, string>> callSite8 = FormMain.Class13.callSite_8;
				if (FormMain.Class13.callSite_9 == null)
				{
					Type type4 = typeof(FormMain);
					CSharpArgumentInfo[] cSharpArgumentInfoArray4 = new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) };
					FormMain.Class13.callSite_9 = CallSite<Func<CallSite, object, object>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags.None, "privacy", type4, cSharpArgumentInfoArray4));
				}
				target3.privacy = _u002103(callSite8, FormMain.Class13.callSite_9.Target(FormMain.Class13.callSite_9, target1));
				GroupData groupDatum3 = groupDatum;
				if (FormMain.Class13.callSite_10 == null)
				{
					FormMain.Class13.callSite_10 = CallSite<Func<CallSite, object, string>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.None, typeof(string), typeof(FormMain)));
				}
				var target4 = FormMain.Class13.callSite_10.Target;
				CallSite<Func<CallSite, object, string>> callSite10 = FormMain.Class13.callSite_10;
				if (FormMain.Class13.callSite_11 == null)
				{
					Type type5 = typeof(FormMain);
					CSharpArgumentInfo[] cSharpArgumentInfoArray5 = new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) };
					FormMain.Class13.callSite_11 = CallSite<Func<CallSite, object, object>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags.None, "email", type5, cSharpArgumentInfoArray5));
				}
				groupDatum3.email = target4(callSite10, FormMain.Class13.callSite_11.Target(FormMain.Class13.callSite_11, target1));
				groupDatas.Add(groupDatum);
			}
			obj = facebookClient.Get("me");
			if (FormMain.Class13.callSite_12 == null)
			{
				FormMain.Class13.callSite_12 = CallSite<Func<CallSite, object, string>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.None, typeof(string), typeof(FormMain)));
			}
			var _u002104 = FormMain.Class13.callSite_12.Target;
			CallSite<Func<CallSite, object, string>> callSite12 = FormMain.Class13.callSite_12;
			if (FormMain.Class13.callSite_13 == null)
			{
				Type type6 = typeof(FormMain);
				CSharpArgumentInfo[] cSharpArgumentInfoArray6 = new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) };
				FormMain.Class13.callSite_13 = CallSite<Func<CallSite, object, object>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags.None, "locale", type6, cSharpArgumentInfoArray6));
			}
			FormMain.mLocale = _u002104(callSite12, FormMain.Class13.callSite_13.Target(FormMain.Class13.callSite_13, obj));
			if (FormMain.Class13.callSite_14 == null)
			{
				FormMain.Class13.callSite_14 = CallSite<Func<CallSite, object, string>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.None, typeof(string), typeof(FormMain)));
			}
			var target5 = FormMain.Class13.callSite_14.Target;
			CallSite<Func<CallSite, object, string>> callSite14 = FormMain.Class13.callSite_14;
			if (FormMain.Class13.callSite_15 == null)
			{
				Type type7 = typeof(FormMain);
				CSharpArgumentInfo[] cSharpArgumentInfoArray7 = new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.Constant, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) };
				FormMain.Class13.callSite_15 = CallSite<Func<CallSite, string, object, object>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.BinaryOperation(CSharpBinderFlags.None, ExpressionType.Add, type7, cSharpArgumentInfoArray7));
			}
			var _u002105 = FormMain.Class13.callSite_15.Target;
			CallSite<Func<CallSite, string, object, object>> callSite15 = FormMain.Class13.callSite_15;
			if (FormMain.Class13.callSite_16 == null)
			{
				Type type8 = typeof(FormMain);
				CSharpArgumentInfo[] cSharpArgumentInfoArray8 = new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) };
				FormMain.Class13.callSite_16 = CallSite<Func<CallSite, object, object>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.GetMember(CSharpBinderFlags.None, "name", type8, cSharpArgumentInfoArray8));
			}
			string str1 = target5(callSite14, _u002105(callSite15, "Profile: ", FormMain.Class13.callSite_16.Target(FormMain.Class13.callSite_16, obj)));
			this.method_0("Login success", false, str1, false);
			this.buttonLogin.Text = "Logout";
		}

		private void buttonRun_Click(object sender, EventArgs e)
		{
			if (this.buttonRun.Text == "Stop")
			{
				this.buttonRun.Text = "Run";
				this.timer_0.Enabled = false;
				return;
			}
			if (this.method_7())
			{
				this.buttonRun.Text = "Stop";
				this.method_0("Ready", false, string.Empty, false);
				for (int i = 0; i < 30; i++)
				{
					Application.DoEvents();
					Thread.Sleep(100);
				}
				if (this.buttonRun.Text == "Stop")
				{
					base.WindowState = FormWindowState.Minimized;
				}
				this.method_5();
			}
		}

		private void buttonSetting_Click(object sender, EventArgs e)
		{
			(new FormSetting(this)).ShowDialog();
		}

		private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
		{
			if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
			{
				this.buttonEdit.PerformClick();
			}
		}

		private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
		{
			DataGridViewColumn item = this.dataGridView1.Columns[e.ColumnIndex];
			AutoSalesContext autoSalesContext = new AutoSalesContext();
			if (item.Name != "StartTime")
			{
				if (item.Name == "Id")
				{
					this.bindingSource_0.DataSource = autoSalesContext.Posts.ToList<Post>();
				}
				return;
			}
			BindingSource bindingSource0 = this.bindingSource_0;
			DbSet<Post> posts = autoSalesContext.Posts;
			ParameterExpression parameterExpression = Expression.Parameter(typeof(Post), "m");
			MemberExpression memberExpression = Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Post).GetMethod("get_StartTime").MethodHandle));
			ParameterExpression[] parameterExpressionArray = new ParameterExpression[] { parameterExpression };
			bindingSource0.DataSource = posts.OrderBy<Post, string>(Expression.Lambda<Func<Post, string>>(memberExpression, parameterExpressionArray)).ToList<Post>();
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && this.icontainer_0 != null)
			{
				this.icontainer_0.Dispose();
			}
			base.Dispose(disposing);
		}

		private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (this.buttonRun.Text == "Stop" && MessageBox.Show("AutoSales is running, do you want to stop and exit now?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No)
			{
				e.Cancel = true;
			}
		}

		private void FormMain_Resize(object sender, EventArgs e)
		{
			if (base.WindowState == FormWindowState.Minimized)
			{
				this.notifyIcon_0.Visible = true;
				this.notifyIcon_0.ShowBalloonTip(5000);
				base.ShowInTaskbar = false;
			}
		}

		private void FormMain_Shown(object sender, EventArgs e)
		{
			this.Cursor = Cursors.WaitCursor;
			Application.DoEvents();
			AutoSalesContext autoSalesContext = new AutoSalesContext();
			if (!this.method_2(autoSalesContext))
			{
				Application.Exit();
				return;
			}
            //054e5a7e886a9dad08cc77e52d9bdc12
			FormMain.mCoca = new Coca(this.licenseInfo.Key);
			this.bindingSource_0.DataSource = autoSalesContext.Posts.ToList<Post>();
			this.dataGridView1.DataSource = this.bindingSource_0;
			this.dataGridView1.Columns["Type"].Visible = false;
			this.dataGridView1.Columns["Id"].Width = 35;
			this.dataGridView1.Columns["Message"].Width = 255;
			this.dataGridView1.Columns["StartTime"].Width = 60;
			this.dataGridView1.Columns["DeleteOldPost"].Width = 55;
			this.dataGridView1.Columns["StopPost"].Width = 55;
			this.Cursor = Cursors.Default;
			Application.DoEvents();
		}

		private void InitializeComponent()
		{
			this.icontainer_0 = new System.ComponentModel.Container();
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(FormMain));
			this.buttonRun = new Button();
			this.timer_0 = new System.Windows.Forms.Timer(this.icontainer_0);
			this.dataGridView1 = new DataGridView();
			this.buttonDelete = new Button();
			this.buttonAdd = new Button();
			this.buttonEdit = new Button();
			this.buttonGroupManage = new Button();
			this.buttonSetting = new Button();
			this.notifyIcon_0 = new NotifyIcon(this.icontainer_0);
			this.buttonLogin = new Button();
			this.statusStrip1 = new StatusStrip();
			this.toolStripStatusLabel1 = new ToolStripStatusLabel();
			this.toolStripProgressBar1 = new ToolStripProgressBar();
			this.toolStripStatusLabel2 = new ToolStripStatusLabel();
			this.linkLabelHelp = new LinkLabel();
			this.linkLabelReport = new LinkLabel();
			this.buttonGroupSearch = new Button();
			((ISupportInitialize)this.dataGridView1).BeginInit();
			this.statusStrip1.SuspendLayout();
			base.SuspendLayout();
			this.buttonRun.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
			this.buttonRun.Location = new Point(701, 235);
			this.buttonRun.Name = "buttonRun";
			this.buttonRun.Size = new System.Drawing.Size(75, 60);
			this.buttonRun.TabIndex = 4;
			this.buttonRun.Text = "Run";
			this.buttonRun.UseVisualStyleBackColor = true;
			this.buttonRun.Click += new EventHandler(this.buttonRun_Click);
			this.timer_0.Interval = 600000;
			this.timer_0.Tick += new EventHandler(this.timer_0_Tick);
			this.dataGridView1.AllowUserToAddRows = false;
			this.dataGridView1.AllowUserToDeleteRows = false;
			this.dataGridView1.AllowUserToResizeRows = false;
			this.dataGridView1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
			this.dataGridView1.BackgroundColor = SystemColors.Menu;
			this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;
			this.dataGridView1.ColumnHeadersHeight = 30;
			this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			dataGridViewCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle.BackColor = Color.Bisque;
			dataGridViewCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle.ForeColor = SystemColors.ControlText;
			dataGridViewCellStyle.SelectionBackColor = SystemColors.Highlight;
			dataGridViewCellStyle.SelectionForeColor = SystemColors.HighlightText;
			dataGridViewCellStyle.WrapMode = DataGridViewTriState.False;
			this.dataGridView1.DefaultCellStyle = dataGridViewCellStyle;
			this.dataGridView1.Location = new Point(12, 12);
			this.dataGridView1.Name = "dataGridView1";
			this.dataGridView1.ReadOnly = true;
			this.dataGridView1.RowHeadersVisible = false;
			this.dataGridView1.RowTemplate.Height = 35;
			this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dataGridView1.Size = new System.Drawing.Size(681, 283);
			this.dataGridView1.TabIndex = 0;
			this.dataGridView1.CellDoubleClick += new DataGridViewCellEventHandler(this.dataGridView1_CellDoubleClick);
			this.dataGridView1.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(this.dataGridView1_ColumnHeaderMouseClick);
			this.buttonDelete.Anchor = AnchorStyles.Top | AnchorStyles.Right;
			this.buttonDelete.Location = new Point(701, 104);
			this.buttonDelete.Name = "buttonDelete";
			this.buttonDelete.Size = new System.Drawing.Size(75, 35);
			this.buttonDelete.TabIndex = 3;
			this.buttonDelete.Text = "Delete";
			this.buttonDelete.UseVisualStyleBackColor = true;
			this.buttonDelete.Click += new EventHandler(this.buttonDelete_Click);
			this.buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
			this.buttonAdd.Location = new Point(701, 12);
			this.buttonAdd.Name = "buttonAdd";
			this.buttonAdd.Size = new System.Drawing.Size(75, 35);
			this.buttonAdd.TabIndex = 1;
			this.buttonAdd.Text = "Add";
			this.buttonAdd.UseVisualStyleBackColor = true;
			this.buttonAdd.Click += new EventHandler(this.buttonAdd_Click);
			this.buttonEdit.Anchor = AnchorStyles.Top | AnchorStyles.Right;
			this.buttonEdit.Location = new Point(701, 58);
			this.buttonEdit.Name = "buttonEdit";
			this.buttonEdit.Size = new System.Drawing.Size(75, 35);
			this.buttonEdit.TabIndex = 2;
			this.buttonEdit.Text = "Edit";
			this.buttonEdit.UseVisualStyleBackColor = true;
			this.buttonEdit.Click += new EventHandler(this.buttonEdit_Click);
			this.buttonGroupManage.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
			this.buttonGroupManage.Location = new Point(12, 301);
			this.buttonGroupManage.Name = "buttonGroupManage";
			this.buttonGroupManage.Size = new System.Drawing.Size(100, 35);
			this.buttonGroupManage.TabIndex = 5;
			this.buttonGroupManage.Text = "Manage Groups";
			this.buttonGroupManage.UseVisualStyleBackColor = true;
			this.buttonGroupManage.Click += new EventHandler(this.buttonGroupManage_Click);
			this.buttonSetting.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
			this.buttonSetting.Location = new Point(224, 301);
			this.buttonSetting.Name = "buttonSetting";
			this.buttonSetting.Size = new System.Drawing.Size(100, 35);
			this.buttonSetting.TabIndex = 6;
			this.buttonSetting.Text = "Setting";
			this.buttonSetting.UseVisualStyleBackColor = true;
			this.buttonSetting.Click += new EventHandler(this.buttonSetting_Click);
			this.notifyIcon_0.BalloonTipIcon = ToolTipIcon.Info;
			this.notifyIcon_0.BalloonTipText = "Click here to active !";
			this.notifyIcon_0.BalloonTipTitle = "AutoSales still run when minimized";
            //this.notifyIcon_0.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("notifyIcon1.Icon");
            //this.notifyIcon_0.Text = "AutoSales | AnhAnh.vn";
			this.notifyIcon_0.Click += new EventHandler(this.notifyIcon_0_Click);
			this.buttonLogin.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
			this.buttonLogin.Location = new Point(330, 301);
			this.buttonLogin.Name = "buttonLogin";
			this.buttonLogin.Size = new System.Drawing.Size(100, 35);
			this.buttonLogin.TabIndex = 7;
			this.buttonLogin.Text = "Login";
			this.buttonLogin.UseVisualStyleBackColor = true;
			this.buttonLogin.Click += new EventHandler(this.buttonLogin_Click);
			ToolStripItemCollection items = this.statusStrip1.Items;
            //ToolStripItem[] toolStripItemArray = new ToolStripItem[] { this.toolStripStatusLabel1, this.toolStripProgressBar1, this.toolStripStatusLabel2 };
            //items.AddRange(toolStripItemArray);
			this.statusStrip1.Location = new Point(0, 340);
			this.statusStrip1.Name = "statusStrip1";
			this.statusStrip1.Size = new System.Drawing.Size(784, 22);
			this.statusStrip1.TabIndex = 13;
			this.statusStrip1.Text = "statusStrip123";
			this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
			this.toolStripStatusLabel1.Size = new System.Drawing.Size(0, 17);
			this.toolStripStatusLabel1.TextAlign = ContentAlignment.MiddleLeft;
			this.toolStripProgressBar1.Name = "toolStripProgressBar1";
			this.toolStripProgressBar1.Size = new System.Drawing.Size(150, 16);
			this.toolStripProgressBar1.Style = ProgressBarStyle.Marquee;
			this.toolStripProgressBar1.Visible = false;
			this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
			this.toolStripStatusLabel2.Size = new System.Drawing.Size(0, 17);
			this.linkLabelHelp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
			this.linkLabelHelp.AutoSize = true;
			this.linkLabelHelp.Location = new Point(517, 312);
			this.linkLabelHelp.Name = "linkLabelHelp";
			this.linkLabelHelp.Size = new System.Drawing.Size(29, 13);
			this.linkLabelHelp.TabIndex = 14;
			this.linkLabelHelp.TabStop = true;
			this.linkLabelHelp.Text = "Help";
			this.linkLabelHelp.LinkClicked += new LinkLabelLinkClickedEventHandler(this.linkLabelHelp_LinkClicked);
			this.linkLabelReport.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
			this.linkLabelReport.AutoSize = true;
			this.linkLabelReport.Location = new Point(461, 312);
			this.linkLabelReport.Name = "linkLabelReport";
			this.linkLabelReport.Size = new System.Drawing.Size(39, 13);
			this.linkLabelReport.TabIndex = 15;
			this.linkLabelReport.TabStop = true;
			this.linkLabelReport.Text = "Report";
			this.linkLabelReport.LinkClicked += new LinkLabelLinkClickedEventHandler(this.linkLabelReport_LinkClicked);
			this.buttonGroupSearch.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
			this.buttonGroupSearch.Location = new Point(118, 301);
			this.buttonGroupSearch.Name = "buttonGroupSearch";
			this.buttonGroupSearch.Size = new System.Drawing.Size(100, 35);
			this.buttonGroupSearch.TabIndex = 16;
			this.buttonGroupSearch.Text = "Search Groups";
			this.buttonGroupSearch.UseVisualStyleBackColor = true;
			this.buttonGroupSearch.Click += new EventHandler(this.buttonGroupSearch_Click);
			base.AutoScaleDimensions = new SizeF(6f, 13f);
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			base.ClientSize = new System.Drawing.Size(784, 362);
			base.Controls.Add(this.buttonGroupSearch);
			base.Controls.Add(this.linkLabelReport);
			base.Controls.Add(this.linkLabelHelp);
			base.Controls.Add(this.statusStrip1);
			base.Controls.Add(this.buttonLogin);
			base.Controls.Add(this.buttonSetting);
			base.Controls.Add(this.buttonGroupManage);
			base.Controls.Add(this.buttonEdit);
			base.Controls.Add(this.buttonDelete);
			base.Controls.Add(this.buttonAdd);
			base.Controls.Add(this.dataGridView1);
			base.Controls.Add(this.buttonRun);
//			base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			base.Name = "FormMain";
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "AutoSales | AnhAnh.vn";
			base.FormClosing += new FormClosingEventHandler(this.FormMain_FormClosing);
			base.Shown += new EventHandler(this.FormMain_Shown);
			base.Resize += new EventHandler(this.FormMain_Resize);
			((ISupportInitialize)this.dataGridView1).EndInit();
			this.statusStrip1.ResumeLayout(false);
			this.statusStrip1.PerformLayout();
			base.ResumeLayout(false);
			base.PerformLayout();
		}

		private void linkLabelHelp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			Process.Start("http://anhanh.vn/help.html");
		}

		private void linkLabelReport_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			(new FormHistory()).Show();
		}

		private void method_0(string string_0, bool bool_2, string string_1, bool bool_3)
		{
			this.method_1(string_0, bool_2, string_1, bool_3, 0, 0);
		}

		private void method_1(string string_0, bool bool_2, string string_1, bool bool_3, int int_1, int int_2)
		{
			Application.DoEvents();
			if (!bool_3)
			{
				this.Cursor = Cursors.Default;
				Application.DoEvents();
			}
			else
			{
				this.Cursor = Cursors.WaitCursor;
				Application.DoEvents();
			}
			if (int_1 != 0 || int_2 != 0)
			{
				ToolStripStatusLabel toolStripStatusLabel = this.toolStripStatusLabel1;
				string[] str = new string[] { "(", int_1.ToString(), "/", int_2.ToString(), ") ", string_0 };
				toolStripStatusLabel.Text = string.Concat(str);
			}
			else
			{
				this.toolStripStatusLabel1.Text = string_0;
			}
			this.toolStripProgressBar1.Visible = bool_2;
			if (string_1 != string.Empty)
			{
				ToolStripStatusLabel toolStripStatusLabel1 = this.toolStripStatusLabel2;
				toolStripStatusLabel1.Text = string.Concat(toolStripStatusLabel1.Text, " | ", string_1);
			}
			Application.DoEvents();
		}

		private bool method_2(AutoSalesContext autoSalesContext_0)
		{
			if (autoSalesContext_0.Registrations.Count<Registration>() > 0)
			{
				Registration registration = autoSalesContext_0.Registrations.FirstOrDefault<Registration>();
				LicenseInfo licenseInfo = new LicenseInfo()
				{
					Value0 = registration.Value0,
					Value1 = registration.Value1,
					Value2 = registration.Value2,
					Value3 = registration.Value3,
					Value4 = registration.Value4,
					Value5 = registration.Value5,
					Value6 = registration.Value6
				};
				this.licenseInfo = licenseInfo;
			}
			Sting.GetLicenseInfo(this.licenseInfo, this.Text);
			if (this.licenseInfo.isActive)
			{
				if (this.licenseInfo.isExpire)
				{
					Registration registration1 = autoSalesContext_0.Registrations.FirstOrDefault<Registration>();
					if (registration1 != null)
					{
						autoSalesContext_0.Registrations.Remove(registration1);
						autoSalesContext_0.SaveChanges();
					}
				}
				if (autoSalesContext_0.Registrations.Count<Registration>() == 0)
				{
					DbSet<Registration> registrations = autoSalesContext_0.Registrations;
					Registration registration2 = new Registration();
					registration2.Value0=(this.licenseInfo.Value0);
                    registration2.Value1=(this.licenseInfo.Value1);
					registration2.Value2=(this.licenseInfo.Value2);
					registration2.Value3=(this.licenseInfo.Value3);
					registration2.Value4=(this.licenseInfo.Value4);
					registration2.Value5=(this.licenseInfo.Value5);
					registration2.Value6=(this.licenseInfo.Value6);
					registration2.Name=(this.licenseInfo.Name);
					registration2.Email=(this.licenseInfo.Email);
					registration2.Phone=(this.licenseInfo.Phone);
					registration2.App=(this.licenseInfo.App);
					registration2.Serial=(this.licenseInfo.Serial);
					registrations.Add(registration2);
					autoSalesContext_0.SaveChanges();
				}
			}
			else if (this.licenseInfo.isExpire)
			{
				Registration registration3 = autoSalesContext_0.Registrations.FirstOrDefault<Registration>();
				if (registration3 != null)
				{
					autoSalesContext_0.Registrations.Remove(registration3);
					autoSalesContext_0.SaveChanges();
				}
			}
			return this.licenseInfo.isActive;
		}

		private string method_3(Post post_0, string string_0, string string_1, FacebookClient facebookClient_0)
		{
			PostData postDatum = new PostData()
			{
				message = post_0.Message.Replace("$group$", string_1)
			};
			postDatum.message = post_0.Message.Replace("$name$", string_1);
			postDatum.picture = post_0.Picture;
			postDatum.link = post_0.Link;
			postDatum.type = post_0.Type;
			return FormMain.mCoca.PostGroup(postDatum, string_0, facebookClient_0);
		}

		private bool method_4(string string_0, FacebookClient facebookClient_0)
		{
			bool target;
			try
			{
				object obj = facebookClient_0.Delete(string_0);
				if (FormMain.Class14.callSite_0 == null)
				{
					FormMain.Class14.callSite_0 = CallSite<Func<CallSite, object, bool>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.None, typeof(bool), typeof(FormMain)));
				}
				target = FormMain.Class14.callSite_0.Target(FormMain.Class14.callSite_0, obj);
			}
			catch
			{
				target = false;
			}
			return target;
		}

		private void method_5()
		{
			AutoSalesContext autoSalesContext = new AutoSalesContext();
			AutoSalesContext autoSalesContext1 = new AutoSalesContext();
			if (autoSalesContext.Posts.Count<Post>() == 0)
			{
				UI.ShowMessage("You must add a post before, click Add button and input your Ads information", UI.MessageType.Error);
				this.buttonRun.Text = "Run";
				return;
			}
			FacebookClient facebookClient = new FacebookClient(FormMain.mToken);
			foreach (Post post in (IEnumerable<Post>)autoSalesContext.Posts)
			{
				FormMain.Class11 class11 = new FormMain.Class11()
				{
					post_0 = post
				};
				Application.DoEvents();
				TimeSpan timeOfDay = DateTime.Now.TimeOfDay;
				timeOfDay = new TimeSpan(timeOfDay.Hours, FormMain.mAnh.RoundDownNumber(timeOfDay.Minutes), 0);
				TimeSpan timeSpan = TimeSpan.Parse(class11.post_0.StartTime);
				timeSpan = new TimeSpan(timeSpan.Hours, FormMain.mAnh.RoundDownNumber(timeSpan.Minutes), 0);
				if (!FormMain.mAnh.TimeEquals(timeOfDay, timeSpan))
				{
					continue;
				}
				int num = 0;
				int count = class11.post_0.Groups.Count;
                //List<Group>.Enumerator enumerator = (List<Group>.Enumerator) class11.post_0.Groups.GetEnuvảmerator();
			    var enumerator = class11.post_0.Groups.GetEnumerator();
				try
				{
					while (true)
					{
						if (enumerator.MoveNext())
						{
							FormMain.Class12 class12 = new FormMain.Class12()
							{
								class11_0 = class11,
								group_0 = enumerator.Current
							};
							Application.DoEvents();
							num++;
							if (this.buttonRun.Text == "Run")
							{
								break;
							}
							if (this.bool_1)
							{
								UI.ShowMessage("Free trial has exceeded the limits, please registered full version to use unlimited features.", UI.MessageType.Warning);
								this.method_0("(Free trial has exceeded the limits)", false, string.Empty, false);
								this.timer_0.Enabled = false;
								return;
							}
							else
							{
								try
								{
									if (class11.post_0.DeleteOldPost)
									{
										DbSet<Logging> loggings = autoSalesContext1.Loggings;
										ParameterExpression parameterExpression = Expression.Parameter(typeof(Logging), "m");
										BinaryExpression binaryExpression = Expression.AndAlso(Expression.Equal(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Logging).GetMethod("get_PostId").MethodHandle)), Expression.Property(Expression.Field(Expression.Constant(class11), FieldInfo.GetFieldFromHandle(typeof(FormMain.Class11).GetField("post_0").FieldHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Post).GetMethod("get_Id").MethodHandle))), Expression.Equal(Expression.Property(parameterExpression, (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Logging).GetMethod("get_GroupId").MethodHandle)), Expression.Property(Expression.Field(Expression.Constant(class12), FieldInfo.GetFieldFromHandle(typeof(FormMain.Class12).GetField("group_0").FieldHandle)), (MethodInfo)MethodBase.GetMethodFromHandle(typeof(Group).GetMethod("get_Id").MethodHandle))));
										ParameterExpression[] parameterExpressionArray = new ParameterExpression[] { parameterExpression };
										foreach (Logging logging in loggings.Where<Logging>(Expression.Lambda<Func<Logging, bool>>(binaryExpression, parameterExpressionArray)))
										{
											this.method_4(logging.FacebookId, facebookClient);
											autoSalesContext1.Loggings.Remove(logging);
										}
									}
									object[] id = new object[] { "Post Id = ", class11.post_0.Id, " to ", class12.group_0.Name };
									this.method_1(string.Concat(id), true, string.Empty, false, num, count);
									string str = this.method_3(class11.post_0, class12.group_0.FacebookId, class12.group_0.Name, facebookClient);
									if (!string.IsNullOrEmpty(str))
									{
										DbSet<Logging> loggings1 = autoSalesContext1.Loggings;
										Logging logging1 = new Logging();
										logging1.PostId=(class11.post_0.Id);
										logging1.GroupId=(class12.group_0.Id);
										logging1.FacebookId=(str);
										logging1.PostTime=(DateTime.Now);
										loggings1.Add(logging1);
										DbSet<History> historys = autoSalesContext1.Histories;
										History history = new History();
										history.CreatedTime=(DateTime.Now);
										history.PostId=(str);
										history.Facebook=(class12.group_0.Name);
										history.Category=((class12.group_0.Category == null ? string.Empty : class12.group_0.Category.Title));
										historys.Add(history);
									}
									autoSalesContext1.SaveChanges();
									if (this.bool_0)
									{
										this.method_6(class11.post_0, num, autoSalesContext);
									}
                                    //else
                                    //{
                                    //    if (this.licenseInfo.isTrial)
                                    //    {
                                    //        FormMain.mAnh.BrowserAction(FormMain.mLocale, "https://www.facebook.com/anhanhsoftware", "Like Me");
                                    //    }
                                    //    if (DateTime.Now.DayOfWeek == DayOfWeek.Friday)
                                    //    {
                                    //        FormMain.mCoca.LikePosts(facebookClient, "anhanhsoftware", 1, 1);
                                    //    }
                                    //    this.bool_0 = true;
                                    //}
								}
								catch (Exception exception)
								{
									UI.ShowMessage(exception, false);
								}
							}
						}
						else
						{
							break;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
				this.method_0("Post completed", false, string.Empty, false);
			}
			this.timer_0.Enabled = true;
		}

		private void method_6(Post post_0, int int_1, AutoSalesContext autoSalesContext_0)
		{
			Application.DoEvents();
			if (int_1 == 0)
			{
				return;
			}
			FormMain int0 = this;
			int0.int_0 = int0.int_0 + 1;
			if (this.licenseInfo.isTrial && (this.int_0 > 20 || autoSalesContext_0.Histories.Count<History>() > 150))
			{
				this.bool_1 = true;
				return;
			}
			int num = (new Random()).Next(60, 90);
            for (int i = 0; i < 100 && !(this.buttonRun.Text == "Run"); i++)
            {
				Application.DoEvents();
				//Thread.Sleep(num * 10);
            }
			if (!string.IsNullOrEmpty(post_0.Picture))
			{
				this.method_0("Pause 3 minutes for each photo upload", false, string.Empty, false);
				for (int j = 0; j < 600 && !(this.buttonRun.Text == "Run"); j++)
				{
					Application.DoEvents();
					//Thread.Sleep(300);
				}
			}
			if (int_1 % 30 == 0)
			{
				this.method_0("Pause 30 minutes for each 30 groups", false, string.Empty, false);
				for (int k = 0; k < 6000 && !(this.buttonRun.Text == "Run"); k++)
				{
					Application.DoEvents();
					//Thread.Sleep(300);
				}
			}
			if (int_1 % 100 == 0)
			{
				this.method_0("Pause 60 minutes for each 100 groups", false, string.Empty, false);
				for (int l = 0; l < 12000 && !(this.buttonRun.Text == "Run"); l++)
				{
					Application.DoEvents();
					//Thread.Sleep(300);
				}
			}
			if (int_1 > 150 && int_1 % 10 == 0)
			{
				this.method_0("Pause 15 minutes (It looks like you were going too fast, please slow down)", false, string.Empty, false);
				for (int m = 0; m < 3000; m++)
				{
					if (this.buttonRun.Text == "Run")
					{
						return;
					}
					Application.DoEvents();
					Thread.Sleep(300);
				}
			}
		}

		private bool method_7()
		{
			bool flag = false;
			if (FormMain.mToken == string.Empty)
			{
				this.buttonLogin.PerformClick();
				flag = (FormMain.mToken == string.Empty ? false : true);
			}
			else
			{
				flag = true;
			}
			return flag;
		}

		private void method_8(out string string_0, out string string_1)
		{
			AutoSalesContext autoSalesContext = new AutoSalesContext();
			string_0 = string.Empty;
			string_1 = string.Empty;
			if (autoSalesContext.Settings.Count<Setting>() > 0)
			{
				Setting setting = autoSalesContext.Settings.FirstOrDefault<Setting>();
				string_0 = setting.UserName;
				string_1 = Anh.Decrypt(setting.Password);
			}
		}

		private void notifyIcon_0_Click(object sender, EventArgs e)
		{
			this.notifyIcon_0.Visible = false;
			base.WindowState = FormWindowState.Normal;
			base.ShowInTaskbar = true;
			base.Activate();
		}

		public void RefreshData(int id, bool editMode)
		{
			DbSet<Post> posts = (new AutoSalesContext()).Posts;
			object[] objArray = new object[] { id };
			Post post = posts.Find(objArray);
			if (!editMode)
			{
				this.bindingSource_0.Add(post);
				this.bindingSource_0.MoveLast();
				return;
			}
			this.dataGridView1.CurrentRow.Cells["Message"].Value = post.Message;
			this.dataGridView1.CurrentRow.Cells["Picture"].Value = post.Picture;
			this.dataGridView1.CurrentRow.Cells["Link"].Value = post.Link;
			this.dataGridView1.CurrentRow.Cells["StartTime"].Value = post.StartTime;
			this.dataGridView1.CurrentRow.Cells["DeleteOldPost"].Value = post.DeleteOldPost;
			this.dataGridView1.CurrentRow.Cells["StopPost"].Value = post.StopPost;
		}

		private void timer_0_Tick(object sender, EventArgs e)
		{
			this.timer_0.Enabled = false;
			this.method_5();
		}

		private sealed class Class11
		{
			public Post post_0;

			public Class11()
			{
			}
		}

		private sealed class Class12
		{
			public FormMain.Class11 class11_0;

			public Group group_0;

			public Class12()
			{
			}
		}

		private static class Class13
		{
			public static CallSite<Func<CallSite, object, IEnumerable>> callSite_0;

			public static CallSite<Func<CallSite, object, object>> callSite_1;

			public static CallSite<Func<CallSite, object, string>> callSite_2;

			public static CallSite<Func<CallSite, object, object>> callSite_3;

			public static CallSite<Func<CallSite, object, string>> callSite_4;

			public static CallSite<Func<CallSite, object, object>> callSite_5;

			public static CallSite<Func<CallSite, object, string>> callSite_6;

			public static CallSite<Func<CallSite, object, object>> callSite_7;

			public static CallSite<Func<CallSite, object, string>> callSite_8;

			public static CallSite<Func<CallSite, object, object>> callSite_9;

			public static CallSite<Func<CallSite, object, string>> callSite_10;

			public static CallSite<Func<CallSite, object, object>> callSite_11;

			public static CallSite<Func<CallSite, object, string>> callSite_12;

			public static CallSite<Func<CallSite, object, object>> callSite_13;

			public static CallSite<Func<CallSite, object, string>> callSite_14;

			public static CallSite<Func<CallSite, string, object, object>> callSite_15;

			public static CallSite<Func<CallSite, object, object>> callSite_16;
		}

		private static class Class14
		{
			public static CallSite<Func<CallSite, object, bool>> callSite_0;
		}
	}
}